package servlet;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Emplist extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
		out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">");
		out.println(" ");
		out.println("<head>");
		out.println("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />");
		out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/layout2_setup.css\" />");
		out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/layout2_text.css\" />");
		out.println("<title></title>");
		out.println("</head>");
		out.println("");
		out.println("<!--[if IE]><style type=\"text/css\"> body {word-wrap: break-word;}</style><![endif]-->");
		out.println("");
		out.println("<body>");
		out.println("<div class=\"page-container\">");
		out.println("");
		out.println("");
		out.println("<div class=\"header\">");
		out.println(" ");
		out.println("<div class=\"header-middle\"> ");
		out.println(" ");
		out.println("<a class=\"sitelogo\" href=\"#\" title=\"Go to Start page\"></a>");
		out.println("<div class=\"sitename\">");
		out.println("<h1><a href=\"index.html\" title=\"Go to Start page\">TARENA<span style=\"font-weight:normal;font-size:50%;\">.com.cn</span></a></h1>");
		out.println("<h2>加拿大大内外企培训</h2>");
		out.println("</div>");
		out.println("");
		out.println("</div>");
		out.println(" ");
		out.println("<div class=\"header-bottom\">");
		out.println(" ");
		out.println("<div class=\"nav2\">");
		out.println(" ");
		out.println("<ul>");
		out.println("<li><a href=\"index.html\">系统首页</a></li>");
		out.println("</ul>");
		out.println(" ");
		out.println("<ul>");
		out.println("<li><a href=\"#\">员工管理<!--[if IE 7]><!--></a><!--<![endif]-->");
		out.println("<!--[if lte IE 6]><table><tr><td><![endif]-->");
		out.println("<ul>");
		out.println("<li><a href=\"#\">员工管理</a></li>");
		out.println("<li><a href=\"#\">添加员工</a></li>");
		out.println("</ul>");
		out.println("<!--[if lte IE 6]></td></tr></table></a><![endif]-->");
		out.println("</li>");
		out.println("</ul> ");
		out.println("");
		out.println("</div>");
		out.println("</div>");
		out.println("");
		out.println("");
		out.println("<div class=\"header-breadcrumbs\">");
		out.println("<ul>");
		out.println("<li><a href=\"#\">首页</a></li>");
		out.println("<li><a href=\"#\">员工管理</a></li>");
		out.println("<li>员工列表</li>");
		out.println("</ul>");
		out.println("");
		out.println(" ");
		out.println("</div>");
		out.println("</div>");
		out.println("");
		out.println("");
		out.println("<div class=\"main\">");
		out.println(" ");
		out.println("<div class=\"main-navigation\">");
		out.println("");
		out.println("<div class=\"round-border-topright\"></div>");
		out.println("<h1 class=\"first\">列表说明<br /></h1>");
		out.println("<p>表格内显示所有员工信息</p>");
		out.println(" ");
		out.println("");
		out.println("");
		out.println(" ");
		out.println("</div>");
		out.println(" ");
		out.println("<div class=\"main-content\">");
		out.println(" ");
		out.println("<h1 class=\"pagetitle\">员工列表</h1>");
		out.println("");
		out.println(" ");
		out.println("");
		out.println(" ");
		out.println("<div class=\"column1-unit\">");
		out.println("<table>");
		out.println("<tr><th class=\"top\" scope=\"col\">员工编号<br /></th><th class=\"top\" scope=\"col\">姓名</th><th class=\"top\" scope=\"col\">工资<br /></th><th class=\"top\" scope=\"col\">入职时间</th></tr>");
		
		
		Connection con = null;
		Statement stm=null;
		ResultSet rs = null;
		try {
			con=DBUtil.open();
			stm=con.createStatement();
			rs=stm.executeQuery("select * from emp");
			while(rs.next()){
				int id = rs.getInt("id");
				String ename=rs.getString("ename");
				double sal= rs.getDouble("sal");
				Date d = rs.getDate("hire_date");
				out.println("<tr><th scope=\"row\">"+id+"</th><td>"+ename+"</td><td>"+sal+"<br /></td><td>"+d+"</td></tr>");
			}
			DBUtil.close(null, stm, rs);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServletException(e);
		} finally {
			DBUtil.close(con, null, null);
		}
		
		
		
		/////////////////////////////////////////
//		out.println("<tr><th scope=\"row\">5092</th><td>张三</td><td>3000.0<br /></td><td>2009-10-09</td></tr>");
//		out.println("<tr><th scope=\"row\">5093</th><td>李四<br /></td><td>3000.0</td><td>2009-02-21</td></tr>");
//		out.println("<tr><th scope=\"row\">5095</th><td>王五</td><td>5000.0</td><td>2009-06-17</td></tr>");
		/////////////////////////////////////////
		
		
		out.println("</table>");
		out.println("<p class=\"caption\"><strong>表 1</strong> 员工列表</p>");
		out.println("</div> ");
		out.println(" ");
		out.println("</div>");
		out.println("</div>");
		out.println(" ");
		out.println("");
		out.println("<div class=\"footer\">");
		out.println("<p>Copyright &copy; 2010 tarena.com.cn | All Rights Reserved</p>");
		out.println("<p class=\"credits\"></p>");
		out.println("</div> ");
		out.println("</div> ");
		out.println(" ");
		out.println("</body>");
		out.println("</html>");
	}
}
